import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

export default defineConfig(({ mode }) => {
  const {
    VITE_API_8090,
    VITE_API_8066,
    VITE_API_9000,
    VITE_API_8000,
    VITE_BASEURL_8090,
    VITE_BASEURL_8066,
    VITE_BASEURL_9000,
    VITE_BASEURL_8000,
  } = loadEnv(mode, process.cwd());

  return {
    base: "/",
    // publicDir: resolve(__dirname, './dist'),
    // assetsInclude: resolve(__dirname, './src/assets'),
    plugins: [vue(), vueJsx(),
      //  createSvgIconsPlugin({
      //   // 图标文件夹为src/assets/icons
      //   iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
      //   // 指定symbolId格式
      //   symbolId: 'icon-[dir]-[name]',
      //  }) 
    ],
    assetsInclude: ["**/*.woff", "**/*.ttf", "**/*.eot", "**/*.svg"], // 处理字体文件

    resolve: {
      alias: [
        {
          find: "@",
          replacement: resolve(__dirname, "src"),
        },
        {
          find: "components",
          replacement: resolve(__dirname, "src/components"),
        },
        {
          find: "vites",
          replacement: resolve(__dirname, "src/view"),
        },
      ],
    },
    server: {
      host: "0.0.0.0",
      port: 3000,
      // 是否开启 https
      https: false,
      proxy: {
         [VITE_BASEURL_8000]: {
          target: VITE_API_8000,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api-8000/, ""),
        },
        [VITE_BASEURL_8090]: {
          target: VITE_API_8090,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api-8090/, ""),
        },
        [VITE_BASEURL_8066]: {
          target: VITE_API_8066,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api-8066/, ""),
        },
        [VITE_BASEURL_9000]: {
          target: VITE_API_9000,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api-9000/, ""),
        },
        "/api": {
          target: "http://127.0.0.1:1001/m1/-0-default/api", // zhao
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
        "/base": {
          // target: "http://10.10.0.200:8219", //开发环境
          target: "http://114.116.13.109:8219", // 测试环境
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/base/, ""),
        },
        "/v2.6": {
          target: "https://api.caiyunapp.com",
          changeOrigin: true,
          ws: true,
        },
        "/geo": {
          target: "https://nx3qqpjfx5.re.qweatherapi.com",
          changeOrigin: true,
          ws: true,
        },
      },
    },
    build: {
      sourcemap: false,
    },
  };
});
